jQuery.jackass = function (params) {
    params = jQuery.extend({
        "scroll_down_key": "j",
        "scroll_up_key": "k",
        "selectors": "p,h1,h2,h3,h4.h5,h6.h7,ul,ol,form",
        "selection_on_load": -1,
        "css_class": "jackass_current",
        "offset_top": 100,
        "background": "",
    }, params);

    var currently_selected = params["selection_on_load"];
    var elements = new Array();
    var count = 0;
    $("*").each(function(){
        if($(this).is(params["selectors"]))
        {
            elements[count] = $(this);
            count += 1;
        }
    });
    var shortkeys_params = {};
    var current_background = "";
    shortkeys_params[params["scroll_down_key"]] = function(){
        if ( currently_selected < elements.length - 1 )
        {
            currently_selected += 1;
        }
        if ( currently_selected > 0 && elements[currently_selected-1].is( "." + params["css_class"] ) )
        {
            elements[currently_selected-1].removeClass( params["css_class"] );
            if( params["background"] )
            {
                elements[currently_selected - 1].css({ background: current_background });
            }
        }
        window.scrollTo(0, elements[currently_selected].addClass( params["css_class"] ).offset().top - params["offset_top"]);
        if( params["background"] )
        {
            current_background = elements[currently_selected].css("background");
            current_background = elements[currently_selected].get(0).style.backgroundColor;
            elements[currently_selected].css({ background: params["background"] });
        }
    }
    shortkeys_params[params["scroll_up_key"]] = function(){
        if ( currently_selected <= 0) return;
        currently_selected -= 1;
        if ( elements[currently_selected+1].is( "." + params["css_class"] ) )
        {
            elements[currently_selected+1].removeClass( params["css_class"] );
            if( params["background"] )
            {
                elements[currently_selected + 1].css({ background: current_background });
            }
        }
        window.scrollTo(0, elements[currently_selected].addClass( params["css_class"] ).offset().top - params["offset_top"]);
        if( params["background"] )
        {
            current_background = elements[currently_selected].css("background");
            current_background = elements[currently_selected].get(0).style.backgroundColor;
            elements[currently_selected].css({ background: params["background"] });
        }
    };
    $(document).shortkeys(shortkeys_params);
}
